-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add contract.gasLeft() #255
base: topic/hardfork-v4
Are you sure you want to change the base?
Conversation
One solution is to use But then other gas related functions should use
|
When the So the It may be useful only to limit gas usage on a called contract. But the method used for that would make the transaction to fail (and the changes be reverted). It would be useful to have a way to set a limit and do not revert the txn, like a protected call that just returns |
Maybe this PR do not need to be applied on V4, and can be left to the next hardfork |
In the current version, gas usage is increased on garbage collection. This means that it is virtually impossible for the user to determine the actual remaining gas since it is executed after the contract function call is returned. We need to change the way gas is calculated first, for this function to be meaningful. |
This is changed on V4, this commit disables gas consumption for garbage collection Although not tested |
But the "remaining gas" is computed based on the transaction "gas limit", and if it is not specified, it is set to UINT64_MAX, even if it is higher than what the account's balance can pay. The reason may be because the account can receive tokens while the transaction is executed, on one of the called contracts, so the execution is not limited on the initial balance of the account It turns out that the number is huge and makes no much sense when used on Maybe this can be implemented later when the gas limit per block is implemented |
This PR adds the
contract.gasLeft()
function to retrieve the remaining gas in the contract executionCloses #239
There is a problem though:
The
lua_pushinteger()
function accepts a value of typelua_Integer
, that is signed int64, and thelua_gasget()
function returns an unsigned int64So if the value of gas is too big, it may appear for the Lua code as a negative value (to be tested)